<?php
namespace Common\Model;

use Think\Model;

class FollowQuestionModel extends Model
{
    /**
     * 统计关注数量
     *
     * @param string $qid
     * @return mixed
     */
    public function get_follow_count($qid = '')
    {
        $map['qid'] = intval($qid);
        $n = $this->where($map)->count();
        return $n;
    }

    /**
     * 检测是否关注过
     *
     * @param string $uid
     * @param string $qid
     * @return bool
     */
    public function chenk_follow_question($uid = '', $qid = '')
    {
        $map['uid'] = intval($uid);
        $map['qid'] = intval($qid);
        $n = $this->where($map)->count();
        if ($n) {
            return true;
        }
        return false;
    }

    /**
     * 关注
     *
     * @param string $uid
     * @param string $qid
     * @return bool
     */
    public function follow_question($uid = '', $qid = '')
    {
        $data['uid'] = intval($uid);
        $data['qid'] = intval($qid);
        $data['addtime'] = time();
        $this->add($data);
        return true;
    }

    /**
     * 取消关注
     *
     * @param string $uid
     * @param string $qid
     * @return bool
     */
    public function clear_follow_question($uid = '', $qid = '')
    {
        $map['uid'] = intval($uid);
        $map['qid'] = intval($qid);
        $this->where($map)->delete();
        return true;
    }
}